Meterpreter has a keylogging command:

**Keylogging works better when we migrate to explorer.exe process **

The commands available:
  1. keyscan_dump ===> Dump the keystroke buffer
  2. keyscan_start ===> Start capturing keystrokes
  3. keyscan_stop ===> Stop capturing keystrokes

Also these are some interesting commands:

  1. keyboard_send ===> Send keystrokes
  2. keyevent ===> Send key events